package com.yanqu.road.server.cmd.activity.horserun;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.HorseRunProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.horserun.HorseRunActivityModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_HORSE_RUN_GET_USER_GAMING_DATA_REQ,desc = "获取玩家游戏中数据")
public class HorseRunGetGamingDataCmd extends AbstractCommand {

    private int activityId;

    private boolean allLog;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        HorseRunProto.HorseRunGetGamingUserDataReq horseRunGetBaseUserDataReq = HorseRunProto.HorseRunGetGamingUserDataReq.parseFrom(packet.getBytes());
        activityId = horseRunGetBaseUserDataReq.getActivityId();
        allLog = horseRunGetBaseUserDataReq.getNeedAllLog();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(HorseRunActivityModule.class).getUserGamingDataReq(activityId,allLog);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            HorseRunProto.HorseRunGetUserGamingDataResp.Builder builder = HorseRunProto.HorseRunGetUserGamingDataResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_HORSE_RUN_GET_USER_GAMING_DATA_REQ, builder);

        }

    }
}
